<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">
	<h:head>
		<title>User List</title>
		<h:outputStylesheet library="css" name="main.css" />
	</h:head>
	<h:body>
	
		<!-- viewUser page only visible to logged-in Admin -->
		<h:panelGroup rendered="#{loginSession.isAdmin()}">
		
			<ui:insert name="header" >
		  		<ui:include src="/templates/header.xhtml" />
			</ui:insert>
			
			<h:form>
				<h:dataTable value="#{usermanager.users}" var="userobject">
					<f:facet name="caption">Registered Users </f:facet>
					
					<h:column>
						<f:facet name="header">#{msgs.edit}</f:facet>
						<h:selectBooleanCheckbox value="#{userobject.editable}" onclick="submit()"/>
					</h:column>
					
					<h:column>
						<f:facet name="header">#{msgs.employeenumber}</f:facet>
						<h:outputText value="#{userobject.employeeNumber}" />
					</h:column>
					
					<h:column>
						<f:facet name="header">#{msgs.username}</f:facet>
						<h:inputText value="#{userobject.userName}" rendered="#{userobject.editable}" />
						<h:outputText value="#{userobject.userName}" rendered="#{!userobject.editable}" />
					</h:column>
					
					<h:column>
						<f:facet name="header">#{msgs.password}</f:facet>
						<h:inputText value="#{userobject.password}" rendered="#{userobject.editable}" />
						<h:outputText value="#{userobject.password}" rendered="#{!userobject.editable}" />
					</h:column>
					
					<h:column>
						<f:facet name="header">#{msgs.lastname}</f:facet>
						<h:inputText value="#{userobject.lastName}" rendered="#{userobject.editable}" />
						<h:outputText value="#{userobject.lastName}" rendered="#{!userobject.editable}" />
					</h:column>
					
					<h:column>
						<f:facet name="header">#{msgs.firstname}</f:facet>
						<h:inputText value="#{userobject.firstName}" rendered="#{userobject.editable}" />
						<h:outputText value="#{userobject.firstName}" rendered="#{!userobject.editable}" />
					</h:column>
					
					<h:column>
						<f:facet name="header">#{msgs.admin}</f:facet>
						<h:selectOneMenu value="#{userobject.admin}" rendered="#{userobject.editable}" >
							<f:selectItem itemValue="false" itemLabel="false"/>
							<f:selectItem itemValue="true" itemLabel="true"/>
						</h:selectOneMenu>
						<h:outputText value="#{userobject.admin}" rendered="#{!userobject.editable}" />
					</h:column>
					
	            	<h:column>
	            		<f:facet name="header">#{msgs.delete}</f:facet>
	               		<h:commandLink value="Delete" action="#{usermanager.deleteUser(userobject)}"/>
	            	</h:column>
					
				</h:dataTable>
				<h:commandButton value="#{msgs.save}" action="#{usermanager.save}" />
				<h:commandButton value="#{msgs.adduser}" action="addUser"/>
			</h:form>
			
		</h:panelGroup>
		
		<!-- Not logged-in viewers will be able to view this section -->
		<h:panelGroup rendered="#{!loginSession.isLoggedIn()}">
			<ui:insert name="notLogIn" >
		  		<ui:include src="/templates/notLogIn.xhtml" />
			</ui:insert>
		</h:panelGroup>
		
		<!-- Logged-in non-admin will be able to view this section -->
		<h:panelGroup rendered="#{!loginSession.isAdmin()}">
			<ui:insert name="notAdmin" >
		  		<ui:include src="/templates/notAdmin.xhtml" />
			</ui:insert>
		</h:panelGroup>
	</h:body>
</html>
